<template>
	<view id="goodsDetail">
		<!-- <web-view :src="url"></web-view> -->
		<view class="wrap">
				<u-swiper height="500" :list="list"  @click="previewImage()"></u-swiper>
				
		</view>
		
		<view class="detail">
			<view class="price">
				<text class="true">¥{{goodsDetail.price}}</text>	
				<text class="market">¥{{goodsDetail.marketPrice}}</text>
				<text class="discount">{{goodsDetail.discount}}折</text>
			</view>
			
			<view class="name">
				{{goodsDetail.goodsName}}
			</view>
			
			
			<view class="guaranteed">
				
100%正品 · 专业鉴定 · 正品险
			</view>
			
			<view class="container" style="background-color: #fff;padding:20rpx;
				margin:20rpx 0;">
				<text style="font-weight: bold;margin-right: 20rpx;">商品参数</text>
				<text>材质、洗涤说明、商品编号等</text>
			</view>
			
			<view class="address" style="background-color: #fff;padding:20rpx;
				margin:20rpx 0;">
				<text style="font-weight: bold;margin-right: 20rpx;">配送至  </text>
				<text>请选择配送地址 <u-icon name="photo" color="#2979ff" size="28"></u-icon></text>

			</view>
			
			<view class="service" style="background-color: #fff;padding:20rpx;
				margin:20rpx 0;">
				上门退货 极速退款 破损无忧 唯品会发货 7天无理由退货 15天质量退 不支持换货 正规发票 唯爱心公益计划
			</view>
			
			<view class="brand">
				
			</view>
			
			<view class="customer">
				
			</view>
			
			<view class="graphic" style="background-color: #fff;padding:20rpx;
				margin:20rpx 0;">
				<text style="font-weight: bold;margin-right: 20rpx;">图文详情</text>
				<view v-for="(pic, index2) in goodsDetail.goodsDetailPictures">
					<!-- <div :style="background:url(pic)"></div> -->
					<image mode="widthFix" @click="previewImage(index2, 'detail')" :src="pic" style="width: 100%;border-radius:5rpx;"></image>
				</view>
			</view>
		</view>
		
		
		<view class="navigation">
			<view class="left">
				<view class="item">
					<u-icon name="server-fill" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">客服</view>
				</view>
				<view class="item">
					<u-icon name="home" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">店铺</view>
				</view>
				<view class="item car" @click="navigateToCart()">
					<u-badge class="car-num" :count="9" type="error" :offset="[-3, -6]"></u-badge>
					<u-icon name="shopping-cart" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">购物车</view>
				</view>
			</view>
			<view class="right">
				<view class="cart btn u-line-1">加入购物车</view>
				<view class="buy btn u-line-1" @click="toSubmit()">立即购买</view>
			</view>
		</view>
		
		<!-- <view class="product-cart" style="position: fixed;bottom: 0;padding:10rpx 0;width: 100%;z-index: 5;background-color: #fff;">
			
			<view>
				<u-icon @click="navigateToCart()" style="float: left;margin-top:10rpx;" label-pos="bottom" label="购物车" name="shopping-cart" size="46"></u-icon>
				<button style="width: 80%;background-color: #f03867;color: #fff;text-align: center;">加入购物车</button>
				<!-- <u-button type="warning" :ripple="true" ripple-bg-color="#f03867" :plain="false">加入购物车</u-button> -->
			<!-- </view>
		</view> --> 
		
		
	</view>
</template>

<script>
	import { convert } from '../../../util/api/request.js'
	export default {
		data() {
			return {
				list: [],
				goodsDetail: {},
					
				goodsId: 0,
				url: ""
			}
		},
		onLoad(options) {
			console.log(options.goodsId)
			this.goodsId = options.goodsId;
			this.url = options.url
		},
		mounted() {
			this.getDetail();
		},
		methods: {
			
			getDetail() {
				let that = this;
				let obj = {};
				obj.goodsId = that.goodsId;
				obj.sid = Math.floor(Math.random()*10000000000000);
				convert( obj ).then(res=>{
					that.list = res.data.goodsCarouselPictures
					that.goodsDetail = res.data;
				})
			},
			
			
			
			/**
			 * @param {Object} pic
			 * 预览图片
			 */
			 previewImage(index, detail) {
				 console.log(index)
				 let list = this.list;
				 if(detail) list = this.goodsDetail.goodsDetailPictures;
				 uni.previewImage({
					urls: list,
					current: index || 0,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			 },
			 
			 /**
			  * 到购物车
			  */
			 navigateToCart() {
				 uni.navigateTo({
				 	url: "/pages/index/shoppingCart/shoppingCart"
				 })
			 },
			 
			 
			 /**
			  * 到提交订单
			  */
			 toSubmit(){
				 let that = this;
			 	uni.navigateTo({
			 	    url: '/pages/index/payment/payment?goodsName='+that.goodsDetail.goodsName+"&goodsPictures="+that.goodsDetail.goodsCarouselPictures[0]
			 	});
			 }
		}
	}
</script>

<style lang="scss" scoped>
.wrap {
		// padding: 40rpx;
	}
	
	
	#goodsDetail{
		background-color: #F8F8F8;
		padding:20rpx;
		.detail{
			margin-bottom: 100rpx;
			.price{
				background-color: #fff;
				padding: 10rpx 0;
				.true{
					font-size: 32rpx;
					color: #f03867;
					margin-right: 20rpx;
				}
				.market{
					color: #999;
					text-decoration:line-through;
					margin:10rpx;
				}
				.discount{
					color: #999;
				}
			}
			
			.name{
				background-color: #fff;
				font-size:32rpx;
				padding-bottom:20rpx;
			}
			
			.guaranteed{
				background-color: #fff;
				padding:10rpx;
				margin:20rpx 0;
			}
		}
	}
	
	
	
	.navigation {
		position: fixed;
		width: 100%;
		bottom: 0;
		display: flex;
		margin-top: 100rpx;
		border: solid 2rpx #f2f2f2;
		background-color: #ffffff;
		padding: 16rpx 0;
		.left {
			display: flex;
			font-size: 20rpx;
			.item {
				margin: 0 30rpx;
				&.car {
					text-align: center;
					position: relative;
					.car-num {
						position: absolute;
						top: -10rpx;
						right: -10rpx;
					}
				}
			}
		}
		.right {
			display: flex;
			font-size: 28rpx;
			align-items: center;
			.btn {
				line-height: 66rpx;
				padding: 0 30rpx;
				border-radius: 36rpx;
				color: #ffffff;
			}
			.cart {
				background-color: #ed3f14;
				margin-right: 30rpx;
			}
			.buy {
				background-color: #ff7900;
			}
		}
	}
	
	
</style>
